package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.PowerCost;
import com.amsp.oa.oademo.service.PowerCostService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Api(tags = "发电费用核算管理")
@RestController
@RequestMapping("/api/powerCost")
public class PowerCostController {

    @Autowired
    private PowerCostService powerCostService;

    @ApiOperation("分页查询发电费用")
    @GetMapping("/page")
    public IPage<PowerCost> getPage(
            @ApiParam(value = "当前页码", required = true) @RequestParam Integer current,
            @ApiParam(value = "每页记录数", required = true) @RequestParam Integer size,
            @ApiParam(value = "负荷名称") @RequestParam(required = false) String loadName) {
        return powerCostService.getPage(current, size, loadName);
    }

    @ApiOperation("保存发电费用")
    @PostMapping("/save")
    public boolean save(@RequestBody List<PowerCost> powerCosts) {
        return powerCostService.saveOrUpdateBatch(powerCosts);
    }

    @ApiOperation("根据ID获取发电费用")
    @GetMapping("/{id}")
    public PowerCost getById(@PathVariable Long id) {
        return powerCostService.getById(id);
    }

    @ApiOperation("删除发电费用")
    @DeleteMapping("/{id}")
    public boolean removeById(@PathVariable Long id) {
        return powerCostService.removeById(id);
    }

    @ApiOperation("批量删除发电费用")
    @DeleteMapping("/batch")
    public boolean removeBatch(@RequestBody List<Long> ids) {
        return powerCostService.removeByIds(ids);
    }
}